$(document).ready(function (){
        //读取登录状态
        var if_login=$.cookie("status");
        //读取用户名
        var username=$.cookie("username");
        
        if(if_login==1){
            $("#login_region").text(username);
            $("#dropdown-login-item").css("display","none");
            $("#dropdown-exit-item").css("display","block");
            
        }else if(if_login==0){
            $("#login_region").text("登录/注册");
            $("#dropdown-login-item").css("display","block");
            $("#dropdown-exit-item").css("display","none");
        }

    


     var data = {
        username:username,
     }
    
        $.ajax({
        type: 'GET',
        url: "http://8.130.103.251:8080/good/getgoodsbyfavortags", 
        data: data,
        ContentType: 'application/json;charset=utf-8',
        
        success: function(data) {   
            console.log(data);
            console.log(data.length);
            for(var i=0;i<data.length;i++){
                var h1=' <div class="recommend-content-item" data-id="'+data[i].goodid+'">';
                var h2='<a href="productDetails.html" target="detail-view" class="item-link">'+'<div class="img-wrapper">'+'<img  src="'+data[i].goodImg1+'">';
                var h3='</div>'+'<div class="info-wrapper">'+'<div class="title">'+data[i].goodName+'</div>'+'</div>';
                var h4='<div class="price-wrapper">'+'<span class="price-value">'+'<em>¥</em>'+'<span>'+data[i].monthPrice+'</span>';
                var h5='<span>/月</span>'+'</span>'+'</div>'+'</a>'+'</div>';
                var content=h1+h2+h3+h4+h5;
                $(".recommend-content-area").append(content);
            }
        },
        error: function(xhr, type) {
            console.log("Error");
        }
     });

});


//分类标签点击事件
$(".catalog-bs a").click(function(){
    var pro_type=$(this).text();
    $.cookie('pro_type',pro_type,{ expires: 7 });
    window.open("tags.html");
})


//将productId存入cookie中
$(".recommend-content-item").on("click",function () { 
    
    var id=$(this).attr("data-id");
    console.log(id);
    $.cookie('productId',id,{ expires: 7 });

})

//动态绑定商品点击事件
$(".recommend-content-area").on("click",".recommend-content-item",function(){
    var id=$(this).attr("data-id");
    console.log(id);
    $.cookie('productId',id,{ expires: 7 });
});

//退出按钮的点击事件
$("#dropdown-exit-item").on("click",function () { 
    $.cookie('username', null);
    $.cookie('status', '0', { expires: 7 });
    location.reload ();
});


//导航栏顶部跳转数码专区
$("#digital-area").click(function(){
    $.cookie('pro_type',"数码配件",{ expires: 7 });
    window.open("tags.html");
});